#include "Client.h"
#include "Console.h"
#include "ConVar.h"
#include "FileSystem.h"
#include "Render.h"

sb3dConVar	*con_fontsize;
sb3dConVar	*con_speed;
sb3dConsole *console;

void sb3dConsole::Init( void )
{
	con_speed = cvars->GetVar( "scr_conspeed", "600", 0, "console moving speed" );
	
	CheckResize();
	
	if( r_width->integer < 640 )
	{
		if( FS_FileExists( "cached/loading400", false ))
			background = render->LoadTexture( "cached/loading400", NULL, 0, TF_IMAGE );
		else background = render->LoadTexture( "cached/loading", NULL, 0, TF_IMAGE );
	}
	else
	{
		if( FS_FileExists( "cached/loading640", false ))
			background = render->LoadTexture( "cached/loading640", NULL, 0, TF_IMAGE );
		else background = render->LoadTexture( "cached/loading", NULL, 0, TF_IMAGE );
	}
	
	initialized = true;
}

void sb3dConsole::CheckResize( void )
{
	
}

void sb3dConsole::Toggle( void )
{
	if( cls.key_dest == key_console )
	{

	}
	else
	{
		cls.key_dest = key_console;
	}
}

void sb3dConsole::DrawConsole( void )
{
	// never draw console whel changelevel in-progress
	if( cls.changelevel )
		return;

	// check for console width changes from a vid mode change
	CheckResize();
	
	// if disconnected, render console full screen
	switch( cls.state )
	{
		case ca_uninitialized:
		break;
		
		case ca_disconnected:
		if( cls.key_dest != key_menu /*&& host.developer*/ )
		{
			DrawSolidConsole( 1.0f );
			cls.key_dest = key_console;
		}
		break;
	case ca_connected:
	case ca_connecting:
		// force to show console always for -dev 3 and higher 
		if( displayFraction ) DrawSolidConsole( displayFraction );
		break;
	case ca_active:
	case ca_cinematic: 
		//if( Cvar_VariableInteger( "sv_background" ))
		//{
			if( cls.key_dest == key_console ) 
				DrawSolidConsole( 1.0f );
		/*}
		else
		{
			if( con.displayFrac )
				Con_DrawSolidConsole( displayFraction );
			else if( cls.state == ca_active && cls.key_dest == key_game )
				Con_DrawNotify(); // draw notify lines
		}*/
		break;
	}
}

void sb3dConsole::DrawSolidConsole( float fraction )
{

}